var cityArr = []; // 区
var districtArr = []; // 乡镇
var ifSuperMan = window.localStorage.getItem("backstage-access-ifSuperMan");

$(function() {
	
  /**
   * 判断超级管理员
   * 1 超级管理员 显示新增按钮
   * 0 普通管理员 隐藏新增按钮
   */
  if (ifSuperMan == 1) {
    $("#bb1").show();
  }
  else {
    $("#bb1").hide();
  }
  var listData = {
    "initData": { //默认参数配置
      "page": "1",
      "pageSize": "10"
    },
    "url": site.apiUrl + "/webInfo/selectWebInfoList", // 数据请求url
    "type": "get",
    // "checkname": "datachk", //选择器名称，为空不显示选择器
    "checkattr": [ //选择器上增加自定义属性，以便传递多个参数
      { "attr": "manager", "value": "{{manager}}" }
    ],
    "col": [ //数据列
      { "field": "webName", "display": "网点名称" },
      { "field": "webAddress", "display": "网点地址" },
    ],
    "option": [ //操作按钮配置  icon: add, repartyorg, ogoto, edit, more, senior, knotitem, del
      { "icon": "ogoto", "tip": "预约设置", "url": "../appointManage/setting.html?webSiteId={{id}}" },
      { "icon": "edit", "tip": "编辑", "url": "edit.html?type=2&id={{id}}" },
      { "icon": "del", "tip": "删除", "fun": "deleteBrand('{{id}}')" }
    ]
  }
  $("#dotList").getList(listData);

  //批量删除
  $("#batchDelBtn").click(function() {
    var c = "";
    $("input[name=datachk]:checked").each(function() {
      c += $(this).val() + ',';
    });
    c = c.substr(0, c.length - 1)
    if (c != null && c != '') {
      deleteBrand(c);
    } else {
      ly.toast("请选择删除项");
    }
  })

})

// 设置默认头像
function changePic(v, o, d) {
  if (d.imgUrl != null && d.imgUrl != '') {
    $(o).html("<img src=" + d.imgUrl + " width='30' height='30'>");
  } else {
    $(o).html("<img src='" + site.interUrl + "/img/default_head.jpg' width='30' height='30'>");
  }
}

// 时间戳转换时间
function changeDate(v, o, d) {
  var baseDateTime;
  var timestamp = new Date(d.creatTime);
  baseDateTime = timestamp.toLocaleDateString().replace(/\//g, "-") + " " + timestamp.toTimeString().substr(0, 8)
  if (d.creatTime != null && d.creatTime != '') {
    $(o).html(baseDateTime)
  }
}

//删除
function deleteBrand(id) {
  ly.confirm("确定删除吗？", function(r) {
    var url = site.apiUrl + "/webInfo/deleteWebInfo";
    request({
      url: url,
      data: { "id": id },
      type: "post",
      callback: function(f) {
        if (f.code == 200) {
          ly.toast("删除成功");
          $("#dotList").getList.refresh(); //刷新当前分页
        } else {
          ly.toast(f.desc || f.msg);
        }
      }
    })
  })
}